from selenium.webdriver.chrome import webdriver
from selenium.webdriver.support.wait import WebDriverWait

from common.doLog import DoLog

lgo = DoLog()
myLogger = lgo.getLogger(__name__)

class BasePage():
    def __init__(self):
        self.driver = webdriver.WebDriver()
        self.driver.get('http://192.168.195.145/user.php')
        self.driver.maximize_window()

    def findEle(self, locator):
        try:
            print('开始查找元素')
            ele = WebDriverWait(self.driver, 10, 1).until(lambda d: d.find_element(*locator))
        except Exception as e:
            print(f"找到元素{locator},异常信息{e}")
            myLogger.error(f'发生异常，信息{e}')
        else:
            print(f'找到元素{locator}')
            myLogger.info('未发生异常')
            return ele
        finally:
            print(f'查找完成{locator}')
            myLogger.info('额不知道')


    def inputText(self, ele, msg):
        try:
            print('向元素中输入内容')
            ele.send_keys(msg)
        except Exception as e:
            print(f'查找元素发生异常{ele},异常信息{e}')
            myLogger.error(f'发生异常，信息{e}')
        else:
            print(f'元素找到了{ele}')
            myLogger.info('未发生异常')
        finally:
            print(f'查找完成{ele}')
            myLogger.info('额不知道')

    def inputText1(self, ele, msg):
        try:
            print('向元素中输入内容')
            ele.send_keys(msg)
        except Exception as e:
            print(f'查找元素发生异常{ele},异常信息{e}')
            myLogger.error(f'发生异常，信息{e}')
        else:
            print(f'元素找到了{ele}')
            myLogger.info('未发生异常')
        finally:
            print(f'查找完成{ele}')
            myLogger.info('额不知道')

    def inputText2(self, ele):
        try:
            print('向元素中输入内容')
            ele.click()
        except Exception as e:
            print(f'查找元素发生异常{ele},异常信息{e}')
            myLogger.error(f'发生异常，信息{e}')
        else:
            print(f'元素找到了{ele}')
            myLogger.info('未发生异常')
        finally:
            print(f'查找完成{ele}')
            myLogger.info('额不知道')